www.gusucode.com > 深度学习(asp)网址导航 v4.0.1 > 深度学习(asp)网址导航 v4.0.1\code\include\Deep.Class.Page.asp
<% '┌──────────────────── 深度空间 深度学习 ──┐ '│深度学习(asp)分页类 (ASP Page Engine) '│Version : 0.0.2 '│作者:吕海鹏 www.deepstudy.cn '│建立时间:2010-2-5 最后修改时间:2010-2-22 '└──────────────────── www.deepstudy.cn ──┘ Class Deep_Page Public pageSize '每页显示记录数 默认10条 Public resultCount '总计录数 Public currentPage '当前页 Private oMyConnection Private Sub Class_Initialize() pageSize=10 ' currentPage=1 End Sub Private Sub Class_Terminate() End Sub '┌──────────────────── 深度空间 深度学习 ──┐ '│过程名:Function PageSQL() '│作 用:分页显示函数 '│参 数: tableName: 表名 '│ dataKeyField: 关键字段 '│ wordField: 欲查询的字段名列表,以","格式分开 '│ whereCondition: 条件 无条件 "" '│ orderByField: 排序方法; 无排序方法"" '│说 明: 通过设置相关查询条件得到复合分页查询SQL语句.适用于Access数据库 '│日 期:2010-2-5 2010-2-22 '└──────────────────── www.deepstudy.cn ──┘ Public function PageSQL( tableName, dataKeyField, wordField, whereCondition, orderByField) dim strSQL:strSQL = "" '每页5条 select top 5 * from 表 where id not in ( select top 10 id from 表) 'SQL server 可以 top为0 access 不能top 0 if (CInt(currentPage) >1) then ' ------ left join iif 方式 start 仅 access ---------------------- 'strSQL="select a.* from ( select top "& (pageSize * (currentPage+1))&" " & wordField & " from " & tableName & " order by " & orderByField& ") a left join ( select top "&(pageSize * currentPage)& " " & wordField & " from " & tableName & " order by " & orderByField& ") b on a."&dataKeyField&"=b."&dataKeyField&" where iif(b."&dataKeyField&",'0','1')='1' " strSQL="select a.* from " strSQL =strSQL & "( select top "&(pageSize * (cint(currentPage)))&" " & wordField & " from " & tableName if (whereCondition <> "") then strSQL =strSQL &" where " & whereCondition End if if (orderByField<>"") then strSQL = strSQL&" order by " & orderByField End if strSQL =strSQL & " ) a " strSQL =strSQL & "left join " strSQL =strSQL & "( select top "&(pageSize * (cint(currentPage)-1))& " " & wordField & " from " & tableName if (whereCondition <> "") then strSQL =strSQL &" where " & whereCondition End if if (orderByField<>"") then strSQL = strSQL&" order by " & orderByField End if strSQL =strSQL & ") b " strSQL =strSQL & "on a."&dataKeyField&"=b."&dataKeyField &" where iif(b."&dataKeyField&",'0','1')='1' " ' ------ left join iif 方式 end 仅 access ---------------------- ' -------- not in 方式 start 效率低 access SQL2000 ------------------------------------------------- ''strSQL = "select top " + PageSize + " * from " + tableName ' + " where " + dataKeyField + " not in ( select top " + ((currentPage - 1) * PageSize) + " " + dataKeyField + " from " + tableName + " order by " + orderByField + ") order by " + orderByField + ""; ' strSQL =strSQL & "select top " & pageSize & " " & wordField & " from " & tableName & " where 1=1 " ' ' if (whereCondition <> "") then ' strSQL =strSQL &" and " & whereCondition ' End if ' strSQL = strSQL & " and " & dataKeyField & " not in ( select top " & ((CInt(currentPage) - 1) * pageSize) & " " & dataKeyField & " from " & tableName& " where 1=1 " ' if (whereCondition <> "") then ' strSQL =strSQL& " and " & whereCondition ' End if ' if (orderByField<>"") then ' strSQL = strSQL&" order by " & orderByField ' End if ' ' strSQL = strSQL & ") " ' ' if (orderByField <> "") then ' strSQL =strSQL & " order by " & orderByField ' End if ' --------- not in 方式 end ------------------------------------------------ else 'strSQL = "select top " + this.PageSize + " * from tArticle"; '当查询为第一页的时候,直接选择 strSQL = "select top " & pageSize & " " & wordField & " from " & tableName if (whereCondition <> "") Then strSQL =strSQL & " where " & whereCondition if (orderByField <> "") Then strSQL = strSQL & " order by " & orderByField End if PageSQL= strSQL '--------------- resultCount=CountSql( tableName, whereCondition) End function '┌──────────────────── 深度空间 深度学习 ──┐ '│过程名:Function PageNavigateUrl() '│作 用:分页导航 显示函数 '│参 数: '│说 明: '│日 期:2009/2/28 2010-2-5 '└──────────────────── www.deepstudy.cn ──┘ Public Function PageNavigateUrl() Dim query, a, x, temp,strHTML : strHTML="" pageCount=1 '总页数 If (resultCount mod pageSize = 0) Then pageCount = resultCount / pageSize Else 'response.write "<br>"& resultCount \ pageSize & "<br>" pageCount = resultCount \ pageSize + 1';//返回最大页数 End if 'resultCount=pDataCount '记录集中总计录数 action = "http://" & Request.ServerVariables("HTTP_HOST") & Request.ServerVariables("SCRIPT_NAME") query = Split(Request.ServerVariables("QUERY_STRING"), "&") For Each x In query a = Split(x, "=") If StrComp(a(0), "page", vbTextCompare) <> 0 Then temp = temp & a(0) & "=" & a(1) & "&" End If Next strHTML = strHTML & ("<div align='center'>") strHTML = strHTML & ("<form method='get' onsubmit=""document.location='" &action& "?" &temp& "Page='+this.page.value;return false;"">") 'strHTML = strHTML & ("<form method='get' action='' >") if (CInt(currentPage)<=1) then strHTML = strHTML & ("[首页] [上一页] ") else strHTML = strHTML & ("[<a href='" & action & "?" & temp & "page=1'>首页</a>] ") strHTML = strHTML & ("[<a href='" & action & "?" & temp & "page=" & (CInt(currentPage)-1) & "'>上一页</a>] ") end if if CInt(currentPage)>=pagecount then strHTML = strHTML & ("[下一页] [尾页]") else strHTML = strHTML & ("[<a href='" & action & "?" & temp & "page=" & (CInt(currentPage)+1) & "'>下一页</a>] ") strHTML = strHTML & ("[<a href='" & action & "?" & temp & "page=" & pagecount & "'>尾页</a>]") end if strHTML = strHTML & (" [页次:<font color='red'>" & currentPage & "</font>/" & pageCount) strHTML = strHTML & ("] [共" & resultCount & "条 <font color='red'>"& pagesize & "</font>条/页]") strHTML = strHTML & (" 转到<input name='page' size='4' value='" & currentPage & "' />页<input type='submit' value='go' />") strHTML = strHTML & ("</form>") strHTML = strHTML & ("</div>") PageNavigateUrl=strHTML End Function '┌──────────────────── 深度空间 深度学习 ──┐ '│过程名:Function CountSql() '│作 用:分页导航 显示函数 '│参 数: '│说 明: 返回一个查看记录总数的SQL语句 '│日 期:2010-2-5 2010-2-5 '└──────────────────── www.deepstudy.cn ──┘ public Function CountSql( tableName, whereCondition) Dim tempSql,rs tempSql = "select count(*) from " & tableName if (whereCondition <> "") then tempSql =tempSql & " where " & whereCondition Set rs=oMyConnection.execute(tempSql) CountSql= rs(0) rs.close set rs=Nothing End function '┌──────────────────── 深度空间 深度学习 ──┐ '│过程名:Function getConnection() '│作 用:得到 ADODB.Connection对象 供CountSql函数调用 '│参 数: '│说 明: '│日 期:2009/2/28 2010-2-5 '└──────────────────── www.deepstudy.cn ──┘ Public function GetConnection(ByRef oADODB_Connection) Set oMyConnection=oADODB_Connection End function End Class %>